package org.egov.dbHandler;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SqlExec {
	private DatabaseConn conn=null;
	private Connection conne=null;
	private Statement st=null;
	private ResultSet rs=null;
	
	public DatabaseConn getConn() {
		return conn;
	}

	public void setConn(DatabaseConn conn) {
		this.conn = conn;
	}

	public Connection getConne() {
		return conne;
	}

	public void setConne(Connection conne) {
		this.conne = conne;
	}

	public Statement getSt() {
		return st;
	}

	public void setSt(Statement st) {
		this.st = st;
	}

	public ResultSet getRs() {
		return rs;
	}

	public void setRs(ResultSet rs) {
		this.rs = rs;
	}

	public ResultSet exectQuery(String sql){
		
		 conn=new DatabaseConn();
		 conne=conn.getConnection();
		 st=null;
		try {
			st=conne.createStatement();
			rs=st.executeQuery(sql);	
		
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}
	
	public boolean exectUpdate(String sql){
		int rs=0;
		 conn=new DatabaseConn();
		 conne=conn.getConnection();
		 st=null;
		try {
			st=conne.createStatement();
			rs=st.executeUpdate(sql);	
			
		
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if(rs!=0){
			return true;
		}else 
			return false;
		
	}
	
	public void close(ResultSet rs,Statement st,Connection connection){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		if(st!=null){
			try {
				st.close();
			} catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		if(connection!=null){
			try {
				connection.close();
			} catch (SQLException e) {				
				e.printStackTrace();
			}
		}
	}
	
}
